package com.xgggh.redpack.domain.redpack;


import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;
import android.os.Parcel;
import android.os.Parcelable;

import com.xgggh.redpack.BR;

import java.util.Date;

public class PackBinding extends BaseObservable implements Parcelable {
    private Long id;

    private String accountId;

    private String accountName;

    private String headerUrl;
    /** 红包分类
     * {@link Category}
     */
    private int category;

    private String fee;

    private String amount;

    private String scope;

    private String targetId;

    private String message;

    private String address="";

    private double latitude;

    private double longitude;
    //领取限制 时间，地点等
    private String useLimited;

    private Date created;

    private Date updated;

    private Date deleted;

    //DecimalFormat decimalFormat = new DecimalFormat("#.###");
    @Bindable
    public String getHeaderUrl() {
        return headerUrl;
    }

    public void setHeaderUrl(String headerUrl) {
        this.headerUrl = headerUrl;
        notifyPropertyChanged(BR.headerUrl);
    }

    @Bindable
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
        notifyPropertyChanged(BR.address);
    }
    @Bindable
    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
        notifyPropertyChanged(BR.latitude);
    }
    @Bindable
    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
        notifyPropertyChanged(BR.longitude);
    }

    public PackBinding(Long id, String accountId, String accountName, int category, String fee, String amount, String scope, String targetId, String message, Date created, Date updated, Date deleted) {
        this.id = id;
        this.accountId = accountId;
        this.accountName = accountName;
        this.category = category;
        this.fee = fee;
        this.amount = amount;
        this.scope = scope;
        this.targetId = targetId;
        this.message = message;
        this.created = created;
        this.updated = updated;
        this.deleted = deleted;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public PackBinding() {
        super();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getAccountId() {
        return accountId;
    }

    public void setAccountId(String accountId) {
        this.accountId = accountId;
    }

    public String getAccountName() {
        return accountName;
    }

    public void setAccountName(String accountName) {
        this.accountName = accountName == null ? null : accountName.trim();
    }

    public int getCategory() {
        return category;
    }

    public void setCategory(int category) {
        this.category = category;
    }

    @Bindable
    public String getFee() {
        return  fee; //decimalFormat.format(fee);
    }

    public void setFee(String fee) {
        this.fee = fee;
        notifyPropertyChanged(BR.fee);
    }

    @Bindable
    public String getAmount() {
        return amount;
    }

    public void setAmount(String amount) {
        notifyPropertyChanged(BR.amount);
        this.amount = amount;
    }

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public String getTargetId() {
        return targetId;
    }

    public void setTargetId(String targetId) {
        this.targetId = targetId;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Date getUpdated() {
        return updated;
    }

    public void setUpdated(Date updated) {
        this.updated = updated;
    }

    public Date getDeleted() {
        return deleted;
    }

    public void setDeleted(Date deleted) {
        this.deleted = deleted;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeValue(this.id);
        dest.writeString(this.accountId);
        dest.writeString(this.accountName);
        dest.writeString(this.headerUrl);
        dest.writeInt(this.category);
        dest.writeString(this.fee);
        dest.writeString(this.amount);
        dest.writeString(this.scope);
        dest.writeString(this.targetId);
        dest.writeString(this.message);
        dest.writeString(this.address);
        dest.writeDouble(this.latitude);
        dest.writeDouble(this.longitude);
        dest.writeString(this.useLimited);
        dest.writeLong(this.created != null ? this.created.getTime() : -1);
        dest.writeLong(this.updated != null ? this.updated.getTime() : -1);
        dest.writeLong(this.deleted != null ? this.deleted.getTime() : -1);
    }

    protected PackBinding(Parcel in) {
        this.id = (Long) in.readValue(Long.class.getClassLoader());
        this.accountId = in.readString();
        this.accountName = in.readString();
        this.headerUrl = in.readString();
        this.category = in.readInt();
        this.fee = in.readString();
        this.amount = in.readString();
        this.scope = in.readString();
        this.targetId = in.readString();
        this.message = in.readString();
        this.address = in.readString();
        this.latitude = in.readDouble();
        this.longitude = in.readDouble();
        this.useLimited = in.readString();
        long tmpCreated = in.readLong();
        this.created = tmpCreated == -1 ? null : new Date(tmpCreated);
        long tmpUpdated = in.readLong();
        this.updated = tmpUpdated == -1 ? null : new Date(tmpUpdated);
        long tmpDeleted = in.readLong();
        this.deleted = tmpDeleted == -1 ? null : new Date(tmpDeleted);
    }

    public static final Creator<PackBinding> CREATOR = new Creator<PackBinding>() {
        @Override
        public PackBinding createFromParcel(Parcel source) {
            return new PackBinding(source);
        }

        @Override
        public PackBinding[] newArray(int size) {
            return new PackBinding[size];
        }
    };
}